package main

import (
	"context"
	"fmt"
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	consul2 "github.com/micro/go-plugins/registry/consul/v2"

	user "user/proto"
)

func main() {
	//注册中心
	consul := consul2.NewRegistry(func(options *registry.Options) {
		options.Addrs = []string{
			"127.0.0.1:8500",
		}
	})
	//链路追踪
	//t, io, err := common.NewTracer("user.client", "8.131.242.167:6831")
	//if err != nil {
	//	log.Fatal(err)
	//}
	//defer io.Close()
	//opentracing.SetGlobalTracer(t)

	service := micro.NewService(
		micro.Name("user.client"),
		micro.Version("latest"),
		micro.Address("127.0.0.1:8085"),
		//添加注册中心
		micro.Registry(consul),
		//绑定链路追踪
		//micro.WrapClient(opentracing2.NewClientWrapper(opentracing.GlobalTracer())),
	)
	userService := user.NewUserService("user", service.Client())
	productAdd := &user.UserRegisterRequest{
		UserName:  "wangzhe1",
		FirstName: "wangzhe",
		Pwd:       "1.1.1.1.1.1",
	}
	response, err := userService.Register(context.TODO(), productAdd)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(response)
}
